package iO;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

//向文件中写入文本数据
public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        //需求： 向demo.txt的文本中写入文本数据
        FileOutputStream fos = new FileOutputStream("./demo.txt");
        String s1 = "hello";
        byte[] b1 = s1.getBytes(StandardCharsets.UTF_8);
        fos.write(b1);

        String s2 = "你好啊";
        b1 = s2.getBytes(StandardCharsets.UTF_8);
        fos.write(b1);
        System.out.println("写出完成");
    }
}
